package collection;

import java.util.ArrayList;
import java.util.Collection;

public class CollectionDemo3 {
    public static void main(String[] args) {
        Collection c1 = new ArrayList();
        c1.add("java");
        c1.add("c++");
        c1.add(".net");
        System.out.println("c1:"+c1);

        Collection c2 = new ArrayList();
        c2.add("android");
        c2.add("ios");
        System.out.println("c2:"+c2);

        c1.addAll(c2);
        System.out.println("c1:"+c1);

        c1.add(c2);
        c2.addAll(c1);
        System.out.println("c1:"+c1);
        System.out.println("c2:"+c2);
        
        Collection c3 = new ArrayList();
        c3.add("java");
        c3.add("php");
        c3.add("c++");
        System.out.println("c3:"+c3);
        
        /*
            boolean retainAll(Collection c)
            仅保留当前集合中与给定集合的共有元素(取交集)
            但是参数集合元素不受影响
         */
        c1.retainAll(c3);
        System.out.println("c1:"+c1);
        System.out.println("c3:"+c3);

        c2.removeAll(c3);
        System.out.println("c2:"+c2);
        System.out.println("c3:"+c3);

        Collection c4 = new ArrayList();
        c4.add("ios");
        c4.add(".net");
        c4.add("mac");
        System.out.println("c4:"+c4);

        boolean containsAll = c2.containsAll(c4);
        System.out.println("完全包含:"+containsAll);
    }
}
